<template>
  <div class="like">
    <div class="title">
      积分换购
    </div>
    <div class="sorting_search_box">
      <div class="sorting_box">
        <div class="sorting_box_item">
          排序:
        </div>
        <div
          v-for="(item,index) in SortingList"
          :key="index"
          class="sorting_box_item sorting_box_item_margin"
          :class="[active === item.type?'sorting_box_item_activ': '']"
          @click="TabActive(item.type)"
        >
          {{ item.name }}
        </div>
      </div>
      <div class="search_box">
        2
      </div>
    </div>
    <div class="goods-list">
      <div
        v-for="item in likeList"
        :key="item.id"
        class="goods-item"
        @click="todetail(item)"
      >
        <div class="goods-img">
          <img
            :src="item.defaultAlbum"
            alt=""
          >
        </div>
        <div class="goods-info">
          <div class="name">
            {{ item.cProductShowName }}{{ item.cModelDescription }}
          </div>
          <div class="price">
            ￥{{ item.fSalePrice }}
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  components: {},
  data() {
    return {
      likeList: [],
      page: 1,
      active: '1',
      SortingList: [{
        id: '1',
        name:'默认',
        type: '1',
      },{
        id: '2',
        name:'价格',
        type: '2',
      },{
        id: '3',
        name:'上架',
        type: '3',
      },{
        id: '4',
        name:'时间',
        type: '4',
      }]
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    //获取列表
    getData() {
      let params = {
        queryCondition: {
          order: [
            {
              fieldname: "iOrder",
              direction: "asc",
            },
          ],
          pagesize: 20,
          pageindex: this.page,
          where: [
            {
              fieldname: "goods_id_exclude",
              valuefrom: "",
            },
            {
              fieldname: "categoryid",
              valuefrom: "",
            },
            {
              fieldname: "type",
              valuefrom: 1,
            },
          ],
        },
      };
      this.$api.home.getRecommendCartList(params).then((res) => {
        if (res.code == 200) {
          // console.log(res.data);
          let more = res.data.data.length % 4;
          this.likeList = res.data.data.splice(more);
        }
      });
    },
    todetail(item) {
      this.$router.push({
        path: "/fruit/detail",
        query: {
          id: item.pid,
          iShopId: item.iShopId
        },
      });
    },
    getmore() {
      this.page++;
      this.getData();
    },
    // tab切换
    TabActive(TabActive) {
      this.active = TabActive
    }
  },
};
</script>

<style scoped lang="scss">
.like {
  padding: 0 16.19rem;
  margin-top: 2.19rem;
  display: flex;
  flex-direction: column;

  .title {
    width: 11.25rem;
    height: 3.44rem;
    background: rgba(0, 0, 0, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.5rem;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: rgba(234, 234, 234, 1);
  }

  .goods-list {
    // margin-top: 1.88rem;
    width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;

    .goods-item {
      width: 17.1rem;
      height: 25.88rem;
      display: flex;
      flex-direction: column;
      align-items: center;
      margin-right: 1.3333333%;
      margin-bottom: 2.38rem;
      cursor: pointer;

      &:nth-child(4n) {
        margin-right: 0;
      }

      .goods-img {
        width: 100%;
        height: 20.94rem;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #fff;

        img {
          width: 16rem;
          height: 16rem;
          object-fit: contain;
        }
      }

      .goods-info {
        width: 17.1rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        margin-top: 1.5rem;

        .name {
          font-size: 1.13rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(0, 0, 0, 1);
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          width: 100%;
        }

        .price {
          font-size: 1.5rem;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: rgba(243, 64, 111, 1);
          margin-top: 0.75rem;
        }
      }
    }
  }
}
.more {
  font-size: 1rem;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: rgba(102, 102, 102, 1);
  line-height: 1.95rem;
  text-align: center;
  margin: 3.13rem auto;
  cursor: pointer;
}

.sorting_search_box{
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 4rem;
  .sorting_box{
    display: flex;
    .sorting_box_item_margin{
      margin: 0 .5rem;
      cursor:pointer
    }
    .sorting_box_item_activ{
      color: rgba(243, 64, 111, 1);
    }
  }
}
</style>
